package com.hudongwx.godoffood.fragment.Adapter;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hudongwx.godoffood.R;
import com.hudongwx.godoffood.activity.Community_Activity.DetailsActivity;
import com.hudongwx.godoffood.activity.home_activity.SubjectActivity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.x;

/**
 * Created by hudongwx on 16-11-5.
 */
public class MyListViewAdapter2 extends BaseAdapter {
    JSONArray specialData;
    Activity activity;

    public MyListViewAdapter2(JSONArray specialData, Activity activity) {
        this.specialData = specialData;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return specialData.length();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final View view = activity.getLayoutInflater().inflate(R.layout.special_select_item2,null);
        TextView textView = (TextView) view.findViewById(R.id.select_item_tv);
        ImageView imageView = (ImageView) view.findViewById(R.id.select_item_iv);

        try {
            JSONObject item = specialData.getJSONObject(position);
            textView.setText(item.getString("Title"));
            x.image().bind(imageView,item.getString("CoverUrl"));

            SubjectClickListener listener = new SubjectClickListener();
            view.setTag(item.getString("Id"));
            view.setOnClickListener(listener);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return view;
    }


    class SubjectClickListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Log.i("SubjectClickListener", "onClick: ");
            Intent intent = new Intent(activity, SubjectActivity.class);
            intent.putExtra("Id",v.getTag()+"");
            activity.startActivity(intent);
        }
    }
}
